package ${packageName}.${moduleName}.service.impl;
<#assign ClassName=StringUtil.firstToUpper(className)>

import java.util.Collections;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.cnlot.booking.base.Page;
import com.cnlot.booking.base.Parameter;
import ${packageName}.domain.${ClassName};
import ${packageName}.${moduleName}.dao.${ClassName}Mapper;
import ${packageName}.${moduleName}.service.${ClassName}Service;

@Service("${className}Service")
public class ${ClassName}ServiceImpl implements ${ClassName}Service{
	private static Logger log = LoggerFactory.getLogger(${ClassName}ServiceImpl.class);
	
	@Autowired ${ClassName}Mapper ${className}Mapper;
	
	@Transactional(propagation=Propagation.REQUIRED,rollbackFor = Exception.class)
	public void create(${ClassName} ${className}){
		if(${className}==null)return;
		${className}Mapper.insert(${className});
	}
	
	@Transactional(propagation=Propagation.REQUIRED,rollbackFor = Exception.class)
	public ${ClassName} get(Long id){
		if(id==null||id<1)return null;
		return ${className}Mapper.selectByPrimaryKey(id);
	}
	@Transactional(propagation=Propagation.REQUIRED,rollbackFor = Exception.class)
	public void update(Parameter parameter){
		if(parameter==null)return;
		${className}Mapper.updateByPrimaryKey(parameter);
	}

	@Transactional(propagation=Propagation.REQUIRED,rollbackFor = Exception.class)
	public void delete(Long id){
		if(id==null||id<1)return;
		${className}Mapper.deleteByPrimaryKey(id);
	}

	@Transactional(propagation=Propagation.REQUIRED,rollbackFor = Exception.class)
	public Page<${ClassName}> list(Page<${ClassName}> page){
		if(page.getTotal()==null||page.getTotal()<1){
			Long total=${className}Mapper.selectCount(page.getFilter());
			if(total==null||total<1){
				page.setTotal(0L);
				page.setList(Collections.<${ClassName}>emptyList());
				return page;
			}
			page.setTotal(total);
		}


		page.setList(${className}Mapper.selectAll(page.buildFilter()));
		if(page.getList()==null){
			page.setList(Collections.<${ClassName}>emptyList());
		}
		return page;
	}

}
